from xml.etree import ElementTree as eleT
text = """
<data>
    <country id="qw" name="Lie">
        <rank updated="yes">2</rank>
        <year>2023</year>
        <neigh direction="E" name="Austria" />
    </country>
    <country name="Per">
        <rank updated="yes">2</rank>
        <year>2024</year>
        <neigh direction="W" name="Costa" />
    </country>
</data>
"""
# 找根节点
root = eleT.XML(text)
# 找节点
node = root.find("country")
# 获取名字
print("获取名字:", node.tag)
# 获取属性
print("获取属性:", node.attrib)
# 遍历节点
print("遍历节点")
for item in node:
    print(item.tag, item.attrib)
# 获取根节点列表
node_all = root.find("country")
